﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ButsaScraperLib;

namespace ForecastManager.Controls
{
	/// <summary>
	/// Interaction logic for TeamWall.xaml
	/// </summary>
	public partial class TeamWall
	{
		public TeamWall()
		{
			InitializeComponent();
		}

		public void PutBricks(List<Team> teams)
		{
			if (Dispatcher.CheckAccess())
			{
				teams = teams
					.OrderByDescending(item => item.TeamName)
					.ToList();

				ClearWall();

				foreach (var team in teams)
				{
					TeamBrick brick = new TeamBrick(team);
					ControlVisualRoot.Children.Add(brick);
				}
			}
			else
			{
				Dispatcher.BeginInvoke(new Action(() => PutBricks(teams)), new object[] { });
			}
		}

		/// <summary>
		/// Очистка стены.
		/// </summary>
		private void ClearWall()
		{
			ControlVisualRoot.Children.Clear();
		}
	}
}
